import {Component, OnInit, Input, ViewChild, OnDestroy, ViewEncapsulation} from '@angular/core';
import {ImageServeService} from "../../service/image/image-serve.service";
import {EventsService} from "../../../core/events/events.service";


@Component({
  selector: 'seed-video',
  templateUrl: './video.component.html',
  styleUrls: ['./video.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class VideoComponent implements OnInit, OnDestroy {
  public _poster: string;
  public _src: string;

  @Input()
  set poster(path: string) {
    this._poster = path;
  }

  get poster(): string {
    return this._poster;
  }

  @Input()
  set src(src: string) {
    this._src = src;
  }

  get src(): string {
    return this._src;
  }

  @ViewChild('video') videoNode;

  constructor(public imgService: ImageServeService,
              public eventService: EventsService) {
    this.reset();
  }

  ngOnInit() {
    this.eventService.subscribe('on-close-popup', val => {
       if (!val) {
         this.videoNode.nativeElement.load();
       }
    });
  }

  reset() {
    this.poster = this.imgService.getLongArticleImgHolder();
    this.src = '';
  }

  ngOnDestroy() {
    this.reset();
  }
}
